package com.android.fragmentdemo.thread9

import org.junit.Test
import java.util.concurrent.locks.ReentrantLock

class Demo9 {
    @Test
    fun testRunnable() {
        val reentrantLock = ReentrantLock(true)
        //val reentrantLock = ReentrantLock(false)
        for (i in 0..4) {
            Thread {
                for (num in 0..1) {
                    try {
                        reentrantLock.lock()
                        println("name:${Thread.currentThread().name},num:${num}")
                    } finally {
                        reentrantLock.unlock()
                    }
                }
            }.start()
        }

        Thread.sleep(5 * 1000)
    }
}